<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件选择模块</title>
</head>
<style>
    .fileSelect-model {
        width: 400px;
        height: 200px;
        border: #666666 solid 1px;
        border-radius: 10px;
    }

    /* 中心上传input */
    #batchUpload {
        visibility: hidden;
    }

    .centerUploadBox {
        cursor: pointer;
        width: 79px;
        height: 30px;
        position: relative;
        top: -20px;
        left: 320px;
    }

    .uploadBut {
        width: 75px;
        height: 30px;
        margin: auto;
        background-color: #1b9aee;
        color: white;
        font-size: small;
        line-height: 30px;
        border-radius: 5px;
    }

    .centerUpload {
        width: 20px;
        height: 20px;
        float: left;
        margin-top: 5px;
        margin-left: 5px;
        text-align: center;
        background-image: url("../static/img/icon/upload.svg");
        background-repeat: no-repeat;
        background-size: cover;
    }

    .uploadChar {
        float: left;
        margin-left: 5px;
    }

    .fileList {
        width: 400px;
        height: 100px;
        overflow: auto
    }

    .uploadSubmit {
        width: 75px;
        height: 30px;
        border-radius: 5px;
        background-color: #1b9aee;
        position: relative;
        top: 165px;
        left: -255px;
        color: white;
        border: none;
    }
</style>
<script>
    // 批量上传
    //通过点击div，对input进行绑定change事件，进而点击div盒子时，可以触发input
    function centerUploadBox() {
        let batchUpload = document.querySelector('#batchUpload');
        let file = document.querySelector(".fileList")
        batchUpload.click();
        batchUpload.addEventListener('change', function () {
            let filesList = document.querySelector('#batchUpload').files;
            if (filesList.length == 0) {
                return;
            } else {
                let arrayFile = "";
                for (let i = 0; i < filesList.length; i++) {
                    arrayFile = "<p>" + filesList[i].name + "</p>" + arrayFile;
                }
                file.innerHTML = arrayFile;

            }
        })
    }


</script>
<body>
<div class="fileSelect-model">
    <!-- 中心上传按钮@click='batchUpload' -->
    <form method="POST" enctype="multipart/form-data" action="/upload">
        <input type="file" id="batchUpload" name="files" accept="image/jpg, image/gif,image/png, image/jpeg"
               multiple="multiple">
        <input type="submit" value="确定" class="uploadSubmit">
    </form>
    <div onclick="centerUploadBox()" class="centerUploadBox">
        <div class="uploadBut">
            <div class="centerUpload"></div>
            <div class="uploadChar">上传</div>
        </div>
    </div>
    <div class="fileList">
    </div>
</div>

</body>
</html>